package com.xoa.service.party;

import com.xoa.dao.party.PointMapper;
import com.xoa.model.party.Point;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by crr on 2018/4/20.
 */
@Service
public class PointService {
    @Autowired
    PointMapper pointMapper;


    /**郭心雨
     * 2018.4.20
     * 根据布控点位id查看所属点位的信息
     * @param conId
     */
    public ToJson<Point> getPointByConId(Integer conId, Integer page, Integer pageSize) {
        ToJson<Point> toJson=new ToJson<Point>();
        Map<String,Object> map=new HashMap<>();
        PageParams pageParams = new PageParams();
        pageParams.setUseFlag(true);
        pageParams.setPage(page);
        pageParams.setPageSize(pageSize);
        map.put("page", pageParams);
        map.put("conId",conId);
        List<Point> pointList=pointMapper.getPointByConId(map);
        toJson.setObj(pointList);
        toJson.setTotleNum(pageParams.getTotal());
        toJson.setFlag(0);
        toJson.setMsg("OK");
        return toJson;
    }

    /**
     * 郭心雨
     * 2018.4.20
     * 根据id修改布控信息
     * @return
     */
    public ToJson updateExecuteById(Point point) {
        ToJson toJson=new ToJson();
        int count=pointMapper.updateByPrimaryKeySelective(point);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("没成功");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 郭心雨
     * 2018.4.20
     * 添加布控信息
     * @param point
     * @return
     */
    public ToJson addExecute(Point point) {
        ToJson toJson=new ToJson();
        int count=pointMapper.insertSelective(point);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("没成功");
            toJson.setFlag(1);
        }
        return toJson;
    }

    /**
     * 郭心雨
     * 2018.4.20
     * 删除点位信息
     * @param pId
     * @return
     */
    public ToJson delExecute(Integer pId) {
        ToJson toJson=new ToJson();
        int count=pointMapper.deleteByPrimaryKey(pId);
        if (count>0){
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("没成功");
            toJson.setFlag(1);
        }
        return toJson;
    }
    public ToJson selectByPrimaryKey(Integer ponitId){
        ToJson toJson=new ToJson();
        Point point=   pointMapper.selectByPrimaryKey(ponitId);
        if (point!=null){
            toJson.setObject(point);
            toJson.setMsg("ok");
            toJson.setFlag(0);
        }else{
            toJson.setMsg("没成功");
            toJson.setFlag(1);
        }
        return toJson;
    }


}
